<?php
class Port extends  Controller
{
	public $type;
	public $table = "dmc010079_db";
    function Port()
    {
        parent::Controller();
      
		header("Content-Type: text/html; charset=utf-8");
		
		
    }
    
    
    function index()//餐厅
    {
    	$query = $this->db->query("select * from ".$this->table.".tipcat_restaurants as a left join ".$this->table.".tipcat_dishes as b on a.restaurantID=b.restaurantID");
    	
    	$row = $query->result_array();
    	
    	$insert = "INSERT INTO `kc_eatery` (
											`eatname` ,
											`tel` ,
											`areaid` ,
											 place,
											`foodtime` ,
											`sendstart` ,
											`sendcost` ,
											`islock` 
											)
											VALUES ";
    	$rowtpl = "(%s,%s,%s,%s,%s,%s,%s,%s),";
    	
    	foreach ($row as $k)
    	{
    		
    		$rows = "";
    		$query1 = $this->db->query("select eateryid from kc_eatery where eatname='".$k["restaurantName"]."'");
    		if($query1->num_rows()>0)
    		{
    			$rs1 = $query1->row_array();
    			$companyid = $rs1["eateryid"];
    		}else
    		{
    			$phone = $k["phoneNumber1"];
	    		if($k["phoneNumber2"]!="")
	    		{
	    			$phone.="或". $k["phoneNumber2"];
	    		}
	    		$rows=sprintf($rowtpl,"'".$k["restaurantName"]."'","'".$phone."'",1,"'".$k["addr"]."'",0,0,0,0);
	    		$rows= substr($rows,0,-1);
    			$this->db->query($insert.$rows);
    			$companyid = $this->db->insert_id();
    		}
    		$query2 = $this->db->query("select foodid from kc_food where foodname='".$k["dishName"]."'");
    		if(!$query2->num_rows>0 && $k["dishName"]!="")
    		{
    			$price = round($k["price"]/10000,2);
    			$this->db->query("INSERT INTO `kc_food` (
													`eatid` ,
													`sortid` ,
													`foodname` ,
													`price` 
													)
													VALUES (
													 ".$companyid.",".$k['dishType'].", '".$k["dishName"]."', ".$price." 
													)");
    		}
    		
    	}
    	echo 'Food And Company Create Finish!';
    	
    }
    function user()
    {
    	$insert = "INSERT INTO `kc_users` (
									    `inviteid` ,
										`username` ,
										`password` ,
										`nickname` ,
										`balance` ,
										`areaid` ,
										`companyid` ,
										`state` ,
										`islock` ,
                                        `lastip` 
										)
										VALUES ";
    	$rowtpl = "(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s),";
    	
    	$query = $this->db->query("select * from ".$this->table.".tipcat_users");
    	$rs = $query->result_array();
    	$rows = "";
    	foreach ($rs as $v)
    	{
    		$query1 = $this->db->query("select userid from `kc_users` where username='".$v["userName"]."'");
    		if(!$query1->num_rows()>0)
    		{
    			$price = round($v["moneyRemain"]/10000,2);
    		$rows.=sprintf($rowtpl,0,"'".$v["userName"]."'","'".md5($v["userPassword"])."'","'".$v["userName"]."'",$price,1,1,0,0,"'".'127.0.0.1'."'");
    		}
    	}
    	$insert.=substr($rows,0,-1);
    	$this->db->query($insert);
    	echo 'User Create Finish!';
    }
    function orders()
    {
    	$query = $this->db->query("select * from ".table("orders")." as o left join ".table("food")." as f on o.foodid=f.foodid left join ".table("users")." as u on o.userid=u.userid where o.isdo=0");
    	
    	$rs = $query->result_array();
    	A($rs);
    	
    	
    }
    function mail()
    {
    	$this->load->library("phpmailer");
    	//设定编码 

		$this->phpmailer->CharSet ="utf-8"; 
		
		$this->phpmailer->IsSMTP(); // send via SMTP 
		
		$this->phpmailer->Host = "smtp.163.com"; // SMTP servers 
		
		$this->phpmailer->SMTPAuth = true; // turn on SMTP authentication 
		
		$this->phpmailer->Username = "hceye"; // SMTP username 
		
		$this->phpmailer->Password = "hc20090310"; // SMTP password 
		
		$this->phpmailer->From = "hceye@163.com"; 
		
		$this->phpmailer->FromName = "苏州东岸内部订餐系统"; 
		
		$this->phpmailer->AddAddress("yangmao726@qq.com","Yang Mao"); 
		
		//$this->phpmailer->AddAddress("zsc@163.com","zsc"); 
		
		//$mail->AddAddress("pietro51@163.com"); // optional name 
		
		//$mail->AddReplyTo("pietro51@163.com","Information"); 
		
		$this->phpmailer->WordWrap = 50; // set word wrap 
		
		//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 
		
		//$this->phpmailer->AddAttachment("C:/Documents and Settings/Administrator/My Documents/My Pictures/123.jpg", "new.jpg"); 
		
		$this->phpmailer->IsHTML(true); // send as HTML 
		
		$this->phpmailer->Subject = "Here is the subject"; 
		
		$this->phpmailer->Body = '<meta http-equiv=content-type content="text/html; charset=utf-8">This is the <b>HTML body</b><font color=red>支持中文</font>'; 
		
		$this->phpmailer->AltBody = "This is the text-only body"; 
		
		if(!$this->phpmailer->Send()) 
		
		{ 
		
			echo "Message was not sent <p>"; 
			
			echo "Mailer Error: ".$this->phpmailer->ErrorInfo; 
			
			exit; 
		
		} 
		
		else 
		{ 
		
			echo "Message has been sent"; 
		
		}

    	
    	
    }
    
    
    
}    
?>